package com.ychen.goods.dao.impl;

import com.ychen.commons.entity.goods.GoodsEntity;
import com.ychen.commons.utils.PageQuery;
import com.ychen.goods.dao.GoodsDao;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class GoodsDaoImpl extends BaseDaoImpl<GoodsEntity> implements GoodsDao {
    @Override
    public List<GoodsEntity> getRecommendGoods(Long userId,Map<String, Object> params) {
        PageQuery<GoodsEntity> pageQuery = new PageQuery<>(params);

        Query query = new Query();
        query.with(new Sort(Sort.Direction.DESC, "supSalesVolume"));
        query.skip(pageQuery.getOffset());
        query.limit(pageQuery.getLimit());
        return mongoTemplate.find(query, GoodsEntity.class, "goodsEntity");
    }
}
